package com.dmpp.mes.service.impl;

import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.ProcessMapper;
import com.dmpp.mes.dao.StationMapper;
import com.dmpp.mes.parameterInfo.Process;
import com.dmpp.mes.parameterInfo.Station;
import com.dmpp.mes.service.ProcessService;
import com.dmpp.mes.service.StationService;
import com.github.pagehelper.PageInfo;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service(value = "StationService")
public class StationServiceImpl implements StationService {
    @Autowired
    private StationMapper mapper;

    @Autowired
    private ProcessMapper processMapper;

    @Override
    public ResponseData findAll(Station station) {
        ResponseData responseData = new ResponseData();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll(station));
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findByCode(String code) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findByCode(code));
        return responseData;
    }

    @Override
    public ResponseData insert(Station station) {
        ResponseData responseData = new ResponseData();
        Station station1= mapper.findByCode(station.getStationCode());
        if (station1==null){
            mapper.insert(station);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateByCode(Station station) {
        ResponseData responseData = new ResponseData();
        mapper.updateByCode(station);
        return responseData;
    }

    @Override
    public ResponseData deleteByCode(String code) {
        ResponseData responseData = new ResponseData();
        Station station = mapper.findByCode(code);
        Process process = processMapper.findByCode(station.getProcessCode());
        if (process==null){
            mapper.deleteByCode(code);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2002);
            System.out.println("有工序包含本工位，不可以删除");
        }

        return responseData;
    }


}
